package com.pybox.repository;

import com.pybox.entity.TObjects;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
* 描述：TObjects Repository
* @author wuyingkai
* @date 2018-09-15
*/

@Repository
public interface TObjectsRepository extends JpaRepository<TObjects, Integer>, JpaSpecificationExecutor<TObjects>   {

    TObjects findByUuid(String uuid);

    @Query(value = "select *  from t_objects where status =?1 and deleted =0 and (is_add_event_log =0 or is_add_event_log is null)",nativeQuery = true)
    List<TObjects> findAllByStatus(Integer status);
    @Query(value = "select  id from t_objects ob where not EXISTS ( select DISTINCT tu.object_id from  t_user_group_objects tu where tu.object_id = ob.id AND tu.object_id is not null)",nativeQuery = true)
    List<Integer> getObjectsNoGroupId();

    @Query(value = "select * from t_objects where status =1 and cabinet_uid=?1 and deleted =0",nativeQuery = true)
    List<TObjects> findBycabinetUid(String cabinetUid);
}